<?php 
$to 		= $_POST['hfr_to'] !== null ? $_POST['hfr_to'] : '';
$name 		= $_POST['hfr_name'] !== null ? $_POST['hfr_name'] : '';
$subject 	= $_POST['hfr_subject'] !== null ? $_POST['hfr_subject'] : '';
$message 	= $_POST['hfr_message'] !== null ? $_POST['hfr_message'] : '';

if ($to != '' && filter_var($to, FILTER_VALIDATE_EMAIL)) {
	
	wp_mail($name." <".$to.">", $subject, $message);
	
	$success_message = "We will reply to your email as soon as.";
} elseif ($to != '' && !filter_var($to, FILTER_VALIDATE_EMAIL)) {
	$error_message = "Your emai is not valid";
} 

?>
<div class="hfr-body">
	<?php echo "<h2 class='title'>". __("Contact us", "hfr_dom") . "</h2>";?>
    <div class="hft-contact">
        <form name="hfr_form" method="post" class="hfr-form-contact" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
        	<?php 
        	if (isset($error_message)) {
        	?>
        	<div class="hfr-alert-danger"><strong>Error! </strong><?=$error_message ?></div>
        	<?php 
        	}
        	?>
        	<?php
        	if (isset($success_message)) {
        	?>
        	<div class="hfr-alert-success"><strong>Thank for contact! </strong><?=$success_message?></div>
        	<?php
        	} 
        	?>
            <table class="form-table">
                <tbody>
                	<tr>
                        <th><label for="hfr_name">Your Name <span class="description">(required)</span></label></th>
                        <td>
                            <input type="text" class="regular-text" value="" id="hfr_name" name="hfr_name" required>
                        </td>
                    </tr>
                	<tr>
                        <th><label for="hfr_to">Your Email <span class="description">(required)</span></label></th>
                        <td>
                            <input type="email" class="regular-text" value="<?=$to != '' ? $to : get_option("hfr_customer")?>" id="hfr_to" name="hfr_to" required>
                        </td>
                    </tr>
                    <tr>
                        <th><label for="hfr_subject">Subject <span class="description">(required)</span></label></th>
                        <td>
                            <input type="text" class="regular-text" value="" id="hfr_subject" name="hfr_subject" required>
                        </td>
                    </tr>
                    <tr>
                        <th><label for="hfr_message">Content <span class="description">(required)</span></label></th>
                        <td>
                            <textarea class="regular-text" id="hfr_message" name="hfr_message" required></textarea>
                        </td>
                    </tr>                    
                </tbody>
            </table>		
            <p class="submit">
                <input type="submit" name="Submit" value="Send Message" class="hfr-btn-blue" />
            </p>
        </form>
    </div>
</div>